<template>
	<el-dialog title="详情" :visible.sync="value" width="370px" :before-close="beforeClose">
		<el-form ref="form" :model="form" label-width="80px">
			<el-form-item label="选择类型" prop="taskIdList">
				<el-checkbox-group v-model="form.taskIdList">
					<el-checkbox v-for="item in taskTypeList" :key="item.value"
						:label="item.value">{{ item.label }}</el-checkbox>
				</el-checkbox-group>
			</el-form-item>
			<el-form-item label="完成状态" prop="isPass">
				<el-radio-group v-model="form.isPass">
					<el-radio :label="true">已完成</el-radio>
					<el-radio :label="false">无法完成</el-radio>
				</el-radio-group>
			</el-form-item>
		</el-form>
		<el-button class="submit-btn" @click="submit">
			提交
			<i class="el-icon-arrow-right"></i>
		</el-button>
	</el-dialog>
</template>
<script>
	import {
		listCheckTask,
		completeCheckTask
	} from '@/api/enterprise'
	export default {
		props: {
			value: {
				type: Boolean,
				default: false
			},
			row: {
				type: Object,
				default: () => null
			}
		},
		watch: {
			row(row) {
				if (row) {
					this.taskList = []
					this.checkTaskTypeDict.forEach(dict => {
						row.checkTaskType.forEach(item => {
							if (item === dict.value) {
								this.taskList.push(dict)
							}
						})
					});
					this.form.enterpriseId = row.id
					this.getListCheckTask()
				}
			}
		},
		data() {
			return {
				taskList: [],
				form: {
					taskIdList: [],
					recordId: '',
					enterpriseId: '',
					isPass: true
				},
				taskTypeList: [],
			}
		},
		computed: {
			checkTaskTypeDict() {
				const dict = this.$store.getters.dict
				const list = []
				for (let value in dict.checkTaskType) {
					list.push({
						label: dict.checkTaskType[value],
						value
					})
				}
				return list
			}
		},
		methods: {
			getListCheckTask() {
				listCheckTask({
					enterpriseId: this.form.enterpriseId,
				}).then((res) => {
					this.taskTypeList = [];
					if (res.data.length > 0) {
						const dict = this.$store.getters.dict
						this.form.recordId = res.data[0].recordId
						res.data.forEach(item => {
							this.taskTypeList.push({
								label: dict.checkTaskType[item.checkTaskType],
								value: item.id
							})
						})
					}
				})
			},
			submit() {
				completeCheckTask(this.form).then((res) => {
					this.$message.success('操作完成')
				})
			},
			beforeClose() {
				this.form = {
					taskIdList: [],
					recordId: '',
					enterpriseId: '',
					isPass: true
				};
				this.$emit('input', false)
			}
		}
	}
</script>
<style lang="scss" scoped>
	::v-deep .el-dialog .el-dialog__body {
		padding: 30px 0 0;
	}

	.el-form {
		padding: 0 10px;
	}

	.check-list {
		padding: 0 40px;
	}

	.submit-btn {
		width: 100%;
		height: 44px;
		background: #1c4088;
		box-shadow: 0px 4px 48px 32px rgba(6, 23, 80, 0.05);
		border-radius: 0;
		color: #ffffff;
		border: none;
	}
</style>